package com.hyh.baowenlioaworking;

import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.PropertySource;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@SpringBootApplication(exclude = {SecurityAutoConfiguration.class })//加上它就解决了
@MapperScan("com.hyh.baowenlioaworking.mapper")
@Slf4j
@EnableTransactionManagement//异常
@PropertySource("classpath:application.yml")
public class BaowenlioaworkingApplication {

    public static void main(String[] args) {

        SpringApplication.run(BaowenlioaworkingApplication.class, args);
        log.info("启动成功！！！！");
    }
    @Bean
    public WebMvcConfigurer webMvcConfigurer(){
        return new WebMvcConfigurer(){
            /**
             * 跨域配置
             * @param registry
             */
            @Override
            public void addCorsMappings(CorsRegistry registry) {
                registry
                        .addMapping("/**")//配置哪些资源允许跨域访问,/**表示根路径下的所有资源
                        .allowedMethods("*")//允许请求访问的方式
                        .allowCredentials(true)//允许使用凭证,cookie
                        .allowedOrigins("http://localhost:8080")//允许访问当前系统的域
                ;

            }
        };
    }



}
